<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Fangattr extends Base
{
    protected $appends = ['pic'];

    // 获取器,从数据库获取数据时添加或更改字段  pic
    public function getPicAttribute()
    {
        $icon = $this->attributes['icon'];
        return config('url.domain') . $icon;
    }


    // 层级显示房源属性
    public function getTreeList()
    {
        $res = session('admin_node');
        if ($res === true) {
            $data = self::get()->toArray();
            return $this->subTree($data);
        }
        $nodes = array_values($res);
        $data  = self::whereIn('id', $nodes)->get()->toArray();
        return $this->subTree($data);
    }

    // 获取全部数据
    public function getAllList()
    {
        // 获取全部数据
        $data = self::get()->toArray();
        // 调用父类中的递归函数
        return $this->treeLevel($data);
    }
}
